package com.zxbg.dao;

import com.zxbg.domain.Department;
import com.zxbg.domain.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DepartmentDao {
    @Select("select * from department where parent is null and tenant_id = #{tenant_Id}")
    public Department getRootNode(Integer tenant_id);

    @Select("select * from department where parent = #{parent} and tenant_id = #{tenant_id} order by `order`")
    public List<Department> getDepartmentByParentDeptId(@Param("parent") Integer parent, @Param("tenant_id") Integer tenant_id);

    @Select("select * from department where dept_id = #{dept_id}")
    public Department getDeptById(Integer dept_id);

    @Update("update department set worker_id = #{worker_id} where dept_id = #{dept_id}")
    public int setWorkerIdByDeptId(@Param("dept_id") Integer dept_id, @Param("worker_id") String worker_id);

    @Update("update department set dept_head = #{dept_head} where dept_id = #{dept_id}")
    public int setDeptHeadByDeptId(@Param("dept_id") Integer dept_id, @Param("dept_head") String dept_head);

    @Insert("insert into department values(null, #{dept_name}, #{tenant_id}, null, #{parent}, null, null, #{order})")
    public int addDepartment(Department department);

    @Select("select * from department order by dept_id desc limit 1")
    public Department getNewDept();

    @Update("update department set children_dept_id = #{children_dept_id} where dept_id = #{dept_id}")
    public int setChildDeptIdByDeptId(@Param("dept_id") Integer dept_id, @Param("children_dept_id") String children_dept_id);

    @Update("update department set dept_name = #{dept_name} where dept_id = ${dept_id}")
    public int setDeptNameByDeptId(Department department);

    @Select("select * from department where parent = #{dept_id} order by `order` desc limit 1")
    public Department getLastChildOrderDept(Integer dept_id);

    @Delete("delete from department where dept_id = #{dept_id}")
    public Integer deleteDept(Integer dept_id);

    @Update("update department set `order` = #{order} where dept_id = #{dept_id}")
    public int setDeptOrderByDeptId(Department department);

    @Select("select * from department where dept_name like #{key} and tenant_id = #{tenant_id}")
    public List<Department> getDeptByNameKey(@Param("key") String key, @Param("tenant_id") Integer tenant_id);
}
